<style lang="less">
@import "@/styles/table-common.less";
.info {
  margin-bottom: 15px;
  ul {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    li {
      width: 25%;
      padding: 5px 0;
    }
  }
}
</style> 
<template>
  <div class="search">
    <Card v-if="companyInfo.companyTypeId">
      <div class="info">
        <h3>企业信息</h3>
        <ul>
          <li>
            <span class="label">企业性质：</span>
            <span>{{ handlefilter(1, companyInfo.companyTypeId) }}</span>
          </li>
          <li>
            <span class="label">企业名称：</span>
            <span>{{ companyInfo.companyName }}</span>
          </li>
          <li>
            <span class="label">行业类型：</span>
            <span>{{ handlefilter(3, companyInfo.companyIndustryId) }}</span>
          </li>
          <li>
            <span class="label">公司规模：</span>
            <span>{{ handlefilter(2, companyInfo.companyScaleId) }}</span>
          </li>
          <li>
            <span class="label">组织证件：</span>
            <a v-if="companyInfo.companyLicense" @click="showBigImg = true"
              >点击查看</a
            >
          </li>
          <li>
            <span class="label">剩余云打印积分：</span>
            <span>{{ companyInfo.companyPrintIntegral }}</span>
            <Button
              type="primary"
              ghost
              v-if="userInfo.type == 1"
              size="small"
              style="margin-left: 15px"
              @click="addintegral(1)"
              >添加</Button
            >
          </li>
          <li>
            <span class="label">剩余预约会议专项积分：</span>
            <span>{{ companyInfo.companyMeetIntegral }}</span>
            <Button
              type="primary"
              ghost
              v-if="userInfo.type == 1"
              size="small"
              style="margin-left: 15px"
              @click="addintegral(2)"
              >添加</Button
            >
          </li>
        </ul>
      </div>
      <div class="info">
        <h3>联系人信息</h3>
        <ul>
          <li>
            <span class="label">姓名：</span>
            <span>{{ companyInfo.user.nickname }}</span>
          </li>
          <li>
            <span class="label">手机号：</span>
            <span>{{ companyInfo.user.mobile }}</span>
          </li>
          <li>
            <span class="label">企业地址：</span>
            <span>{{ companyInfo.companyAddress }}</span>
          </li>
        </ul>
      </div>
    </Card>
    <Card>
      <Tabs :animated="false">
        <TabPane label="人员管理"><Person :companyId="companyId" /></TabPane>
        <TabPane label="商品">
          <shop-goods-statistic :companyId="companyId"></shop-goods-statistic>
        </TabPane>
      </Tabs>
    </Card>
    <Modal title="组织证件" v-model="showBigImg">
      <img
        :src="companyInfo.companyLicense"
        v-if="showBigImg"
        style="width: 100%"
      />
    </Modal>
  </div>
</template>

<script>
import Person from "./person/person";

import {
  getCompanyDetailById,
  getCompanyScale,
  getCompanyType,
  getFindAll,
  addMeetIntegral,
  addPrintIntegral,
} from "@/api/index";
import ShopGoodsStatistic from "./shopGoodsStatistic.vue";

export default {
  name: "company-info",
  components: {
    Person,
    ShopGoodsStatistic,
  },
  data() {
    return {
      showBigImg: false,
      addIntegral: "",
      userInfo: JSON.parse(localStorage.getItem("userInfo")),
      companyTypeList: [], //企业类型列表
      companyScaleList: [], //企业规模列表
      companyNatureList: [], //企业性质列表
      message: "",
      height: 510,
      showUser: false,
      showType: "0",
      loading: true,
      data: [],
      companyInfo: {},
      adminInfo: {},
      companyId: "",
    };
  },
  methods: {
    addintegral(type) {
      this.addIntegral = "";
      let _this = this;
      let text = "";
      if (type == 1) {
        //云打印
        text = "添加云打印积分";
      } else if (type == 2) {
        //会议积分
        text = "添加预约会议专项积分";
      }
      this.$Modal.confirm({
        title: text,
        render: (h) => {
          return h("Input", {
            props: {
              value: this.addIntegral,
              autofocus: true,
              type: "number",
              placeholder: "请输入要添加的积分数",
            },
            on: {
              input: (val) => {
                this.addIntegral = val;
              },
            },
          });
        },
        onOk: function () {
          if (type == 1) {
            addPrintIntegral({
              id: _this.companyId,
              num: _this.addIntegral,
            }).then((RES) => {
              _this.$Modal.remove();
              _this.getCompanyDetailById();
            });
          } else if (type == 2) {
            addMeetIntegral({
              id: _this.companyId,
              num: _this.addIntegral,
            }).then((RES) => {
              _this.$Modal.remove();
              _this.getCompanyDetailById();
            });
          }
        },
      });
    },
    handlefilter(type, val) {
      if (type == 1) {
        //企业性质
        console.log(val);
        console.log(this.companyTypeList);
        let obj = this.companyNatureList.find((item) => item.id == val);
        return obj.title || "";
      } else if (type == 2) {
        //企业规模
        let obj = this.companyScaleList.find((item) => item.id == val);
        return obj.title || "";
      } else if (type == 3) {
        //行业类型
        let obj = this.companyTypeList.find((item) => item.id == val);
        return obj.title || "";
      }
    },
    getCompanyDetailById() {
      getCompanyDetailById({ companyId: this.companyId }).then((res) => {
        console.log(res);
        if (res.code == 200) {
          this.companyInfo = res.result;
        }
      });
    },
  },
  async created() {
    this.companyId = localStorage.getItem("companyId");
    await getFindAll().then((res) => {
      if (res.success) {
        this.companyNatureList = res.result;
      }
    });
    await getCompanyType().then((res) => {
      if (res.success) {
        this.companyTypeList = res.result;
      }
    });
    await getCompanyScale().then((res) => {
      if (res.success) {
        this.companyScaleList = res.result;
      }
    });
    let _this = this;
    setTimeout(() => {
      _this.getCompanyDetailById();
    }, 500);
  },
  mounted() {},
};
</script>